package psrc.logic.pages.fabrica;

import java.sql.SQLException;
import java.util.List;

import psrc.bd.dao.FabricaDAO;
import psrc.logic.util.beans.FabricaBean;

public class FabricaModel {
	
	public FabricaDAO dao = new FabricaDAO(null);

	public List<FabricaBean> getFabricasList() throws Exception{
		return dao.seleciona();
	}
	
	public boolean removeFabrica (List<FabricaBean> fabricas) throws Exception{
		try{
			for (FabricaBean bean : fabricas){
				dao.remove(bean);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		return true;
	}

	public boolean insert(FabricaBean bean) {
		try {
			dao.adiciona(bean);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return true;
	}
	
	public void update(FabricaBean bean) {
		try {
			dao.edita(bean);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public FabricaBean getObjectById(String id){
		FabricaBean bean = new FabricaBean();
		bean.setIdFabrica(id);
		try {
			return dao.selecionaPorId(bean).get(0);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}

}
